package com.gilgamesh.mall.member.controller;

import com.gilgamesh.mall.member.service.UserService;
import com.gilgamesh.mall.sdk.bean.member.UserEntity;
import com.gilgamesh.mall.sdk.client.member.UserClient;
import com.gilgamesh.mall.sdk.dto.ResponseDTO;
import com.gilgamesh.mall.sdk.dto.member.UserDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yanm
 * @date 2021/1/12 17:14
 **/
@RestController
@RequestMapping("api/member")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class UserController implements UserClient {

    private final UserService userService;

    @Override
    @PostMapping("add")
    public ResponseDTO<Integer> add(@RequestBody UserEntity user) {
        return userService.add(user);
    }

    @Override
    @PostMapping("login")
    public ResponseDTO<UserDTO> check(@RequestParam(value = "number", required = false) String number,
                                      @RequestParam(value = "password", required = false) String password){
        UserEntity user = new UserEntity();
        user.setNumber(number);
        user.setPassword(password);
        return userService.check(user);

    }
//
    @Override
    public ResponseDTO<String> geMailVerifiCode(String mail, String password) {
        UserEntity user = new UserEntity();
        user.setMail(mail);
        user.setPassword(password);
        return userService.geMailVerifiCode(user);
    }

    @Override
    public ResponseDTO<Integer> verifiyAndRegisterMail(String mail, String password, String verifiCode) {
        UserEntity user = new UserEntity();
        user.setMail(mail);
        user.setPassword(password);
        user.setVerifiCode(verifiCode);
        return userService.verifiyAndRegisterMail(user);
    }

    @Override
    public ResponseDTO<Integer> registerByPhone(String phone, String password) {
        UserEntity user = new UserEntity();
        user.setPhoneNumber(phone);
        user.setPassword(password);
        return userService.registerByPhone(user);
    }

    @Override
    public ResponseDTO<Integer> queryMail(String mail) {
        return userService.queryMail(mail);
    }


}
